﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using DAO;
using DTO;
namespace BUS
{
  public class DiaDiemBUS
    {
      public static List<DiaDiemDTO> danhSachDiaDiemTheoTenQuocGia(String sTenQuocGia, String sStrPath)
      {
          return DiaDiemDAO.danhSachDiaDiemTheoTenQuocGia(sTenQuocGia, sStrPath);
      }
      public static List<DiaDiemDTO> danhSachDiaDiemTheoQuery(String query, String sStrPath)
      {
          List<DiaDiemDTO> listDiaDiem = new List<DiaDiemDTO>();
          ArrayList listInfoQuery=chuyenQuerySangDiaDiem(query);
          if (listInfoQuery.Count == 1)
          {
              
              listDiaDiem = DiaDiemDAO.danhSachDiaDiemTheoTenQuocGia(listInfoQuery[0].ToString(), sStrPath);
          }
          if (listInfoQuery.Count > 1)
          {
              listDiaDiem = DiaDiemDAO.danhSachDiaDiemTheoQuery(listInfoQuery, sStrPath); 
          }
          
          return listDiaDiem;
      }
      public static  String xoaKhoangTrang(string strChuoi)
      {
          //Thuc hien viec xoa khoang trang
          string ketQua = "";

          bool flag = false;
          if (strChuoi.Length > 0)
          {
              for (int i = 0; i < strChuoi.Length; i++)
              {
                  char syllable = strChuoi[i];
                  if (syllable.Equals(' ') == false)
                  {
                      ketQua = ketQua + syllable;
                      flag = true;
                  }
                  else
                  {
                      if (flag == true)
                      {
                          ketQua = ketQua + ' ';
                          flag = false; ;
                      }
                  }
              }
              int lenght = ketQua.Length;
              if (ketQua[lenght - 1].Equals(' ') == true)
              {

                  ketQua = ketQua.Substring(0, lenght - 1);
              }
              ketQua = ketQua.ToLower();
          }
          return ketQua;

      }

      public static ArrayList chuyenQuerySangDiaDiem(String query)
      {
          ArrayList list = new ArrayList();
          String[] listQuery = query.Split(',');
          for (int i = listQuery.Length-1; i >=0; i--)
          {
              String value = listQuery[i];
              value = xoaKhoangTrang(value);
              list.Add(value);
          }
          return list;
      }
    }
}
